import { CLEARUSERINFO, SETUSERINFO } from '@/redux/constant.js';
let initData = {}
let data =localStorage.getItem('userInfo');
if(data !== undefined && data != '{}'){
  initData = JSON.parse(data)
}
export default function User_reducer(preState = initData, action){
  const {type,data} = action
  switch (type){
    case SETUSERINFO:
      localStorage.setItem('userInfo',JSON.stringify(data));
      return data
    case CLEARUSERINFO:
      localStorage.removeItem('userInfo');
      return {}
    default :
      localStorage.setItem('userInfo',JSON.stringify(initData));
      return initData
  }
}
